package com.guchenbo.example.thread;

import java.util.concurrent.*;

/**
 * @Author guchenbo
 * @Date 2019/7/30.
 */
public class VolatileTest {

    private  static  boolean flag = false;

    private static ExecutorService threadPool = new ThreadPoolExecutor(8, 32, 60L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<>(), new ThreadFactory() {
        private int count = 0;
        private String prefix = "crawler-manager";

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, prefix + "-" + count++);
        }
    });

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 20; i++) {
            threadPool.submit(()->{
//                while (!flag){
                                        System.out.println("do");
//                }
                System.out.println(Thread.currentThread().getName()+flag);
            });
        }

        Thread.sleep(2000);

        flag = true;
    }
}
